home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagn_r.zip / NUMBERS.SWG / 0008_BYTE2BIN.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  707b  |  42 lines

  1. {
  2. Byte to Binary...
  3. }
  4.  
  5. Type
  6.   String8 = String[8];
  7.  
  8.  
  9. Function Byte2Bin(byTemp : Byte) : String8;
  10. Var
  11.   Count : Integer;
  12. begin
  13.   Byte2Bin[0] := #8;
  14.   For Count := 0 to 7 do
  15.     Byte2Bin[8 - Count] := Char(((byTemp shr Count) and 1) + ord('0'));
  16. end;
  17.  
  18. Function Byte2BinAsm(byTemp : Byte) : String8; Assembler;
  19. Asm
  20.   push    ds
  21.   les     di,@result
  22.   mov     ah,byTemp
  23.   mov     cl,8
  24.   mov     al,cl
  25.   stosb
  26. @loop:
  27.   mov     al,24
  28.   add     ah,ah
  29.   adc     al,al
  30.   stosb
  31.   loop    @loop
  32.   pop     ds
  33. end;
  34.  
  35. begin
  36.   Writeln;
  37.   Writeln('10 in Binary = ',Byte2Bin(10));
  38.   Writeln;
  39.   Writeln('The same thing With assembly code: ',Byte2BinAsm(10));
  40.   Writeln;
  41.   Readln;
  42. end.